<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>影院管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">

</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" method="post" action="${path}/cinames/findAll">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">电影院名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="name" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit
                                    lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add">添加电影院</button>
                <%--<button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete">批量删除</button>--%>
            </div>
        </script>

        <table class="layui-table" id="currentTableId" lay-filter="currentTableFilter" lay-data="{url:'${path}/cinames/findAll',toolbar: true,toolbar: '#toolbarDemo', page: true, limit: 10, limits:[10,15,20],height: 650}">
            <thead>
            <tr>
                <th lay-data="{checkbox:true,width:60 , align: 'center'}" rowspan="2"></th>
                <th lay-data="{field:'id',width:60 , align: 'center',hide:true}" rowspan="2"></th>
                <th lay-data="{field:'tid', width:60, title: '序号',templet:'#zizeng', align: 'center'}" rowspan="2"></th>
                <th lay-data="{field:'name', width:300,align:'center'}" rowspan="2">电影院名</th>
                <th lay-data="{field:'location', width:150,align:'center'}" colspan="3">地区</th>
                <th lay-data="{fixed: 'right', width: 160, align: 'center', toolbar: '#barDemo'}" rowspan="2">操作</th>
            </tr>
            <tr>
                <th lay-data="{field:'province', align: 'center', width:120}">省</th>
                <th lay-data="{field:'city', align: 'center', width:120}">市</th>
                <th lay-data="{field:'area', align: 'center', width:120}">区</th>
            </tr>
            </thead>
        </table>

        <div id="test"></div>
        <script type="text/html" id="barDemo">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>

    </div>

</div>
<script src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../js/lay-module/tableSelect/tableSelect.js"></script>
<script type="text/html" id="zizeng">
    {{d.LAY_TABLE_INDEX+1}}
</script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;


        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            let result = JSON.stringify(data.field);
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');
            //执行搜索重载
            return false;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '添加电影院',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: 'add.jsp',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            }
        });


        table.on('tool(currentTableFilter)', function (obj) {
            let data = obj.data;
            if (obj.event === 'edit') {
                let index = layer.open({
                    title: '编辑电影院信息',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: 'edit.jsp',
                    success:function(layero, index) {
                        let iframe = window['layui-layer-iframe' + index];
                        iframe.child(data);
                    }
                });
                $(window).on("resize", function () {
                    layer.full(index);
                })
                return false;
            } else if (obj.event === 'delete') {
                let state = obj.tr.children().eq(13).find(".data-count-delete").text()
                let path ;
                layer.confirm('确认删除该影院吗', function (index) {
                    $.post('${path}/cinames/deleteById',{"id":data.id},function (result){
                        if(result.code=="200"){
                            layer.msg('删除成功！', {icon:1});
                            table.reload("currentTableId",{
                                page:{
                                    curr: $(".layui-laypage-em").next().html()
                                }
                            });
                        }else {
                            layer.msg('删除失败！', {icon:2});
                        }
                    })

                    layer.close(index);
                });
            }
            });


        //监听单元格编辑
        table.on('edit(currentTableFilter)', function(obj){
            var value = obj.value //得到修改后的值
                ,data = obj.data //得到所在行所有键值
                ,field = obj.field; //得到字段
            layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为：'+ value);
        });
    });


</script>
</body>
</html>